#pragma once

#include "Camera.h"
#include "GBox.h"
#include "ISelect.h"
#include "HighLight.h"
#include "Preview.h"

class CGraphicsPlatform;

class CGViewer
{
public:
	CGViewer(CGraphicsPlatform* pParent);
	virtual ~CGViewer(void);

	enum OperateType
	{
		eNoneOperate = -1,
		eRotate,
		ePan,
		eZoom,
		eSelect,
		ePreSelectMore,
		ePreSelect,
	};

// method
public:
	void							Fit(CGBox& oBox);

	CCamera*						GetCamera() { return &m_oCamera; }
	CSelectSet*						GetSelectSet() { return &m_oSelectSet; }
	CHighLightSet*					GetHighLightSet() { return &m_oHighLightSet; }
	CLineArrowGraphics*				GetPreviewObject();
	CCoordinateSystemGraphics*		GetCSGraphics();
	CGraphicsPlatform*				GetParent() { return m_pParent; }

	bool							IsOperating() { return m_bOperating; }
	void							StartRotate(int iPtX, int iPtY);
	void							StartPan(int iPtX, int iPtY);
	void							StopOperate();
	void							OnRotate(int iPtX, int iPtY);
	void							OnPan(int iPtX, int iPtY);
	void							OnZoom(double dScale);
	void							Update(int iPtX, int iPtY);

	void							ViewToModelSpace(int iPtX, int iPtY, CVec& pt);
	void							ModelSpaceToView(const CVec& pt, int& iPtX, int& iPtY);
	void							GetScreenPt(int& iViewPtX, int& iViewPtY);

	bool							Reset();

protected:
	void							Rotating(int iDeltaX, int iDeltaY);
	void							Panning(int iDeltaX, int iDeltaY);

public:
// property
	void							SetViewRange(int iWidth, int iHeight);
	void							GetViewRange(int& iWidth, int& iHeight);
	void							SetOperateType(OperateType eType) { m_eOperateType = eType; }
	OperateType						GetOperateType() { return m_eOperateType; }

private:
	CCamera							m_oCamera;
	CGBox							m_box;
	CSelectSet						m_oSelectSet;
	CHighLightSet					m_oHighLightSet;
	CLineArrowGraphics*				m_pArrowPreview;
	CCoordinateSystemGraphics*		m_pCSGraphics;
	double							m_dSmallDistance;
	int								m_iViewWidth;
	int								m_iViewHeight;
	int								m_iViewPtX;
	int								m_iViewPtY;
	OperateType						m_eOperateType;
	bool							m_bOperating;
	CGraphicsPlatform*				m_pParent;
	
};
